Function: Rename/Replace Enumeration Value of a DataType

Hi!

Has someone already written a function, that renames an existing Enumeration value?

I need s.th. like this:

setEnumerationFromTo(Module mod, AttrType type, string oldValue, string newValue)

By default the functions is under Edit -> Types -> Select Enum DataType -> Tab Enumerations -> Mark old on the right -> Type in the textinputs -> Press replace

With best regards,
Bjoern


Bjoern_Karpenstein - Thu Oct 15 03:48:19 EDT 2015

Re: Function: Rename/Replace Enumeration Value of a DataType
Pekka_Makinen - Thu Oct 15 05:00:08 EDT 2015

See https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000014277834

Re: Function: Rename/Replace Enumeration Value of a DataType
Bjoern_Karpenstein - Thu Oct 15 05:21:04 EDT 2015

Hi thanks for your reply.

Only one question:

Is the following function save in the way, that enumeration values that already have been set in the module will not get lost?

void replaceAttributeTypeValue(Module m, string atName, string oldVal, string newVal){
    AttrType att = find(m, atName)
        //Declare Arrays Size
        int colores[att.size]
        int arrMap[att.size]
        string arr[att.size]
        int arrVal[att.size]
        
        int i
        //Populate Arrays
        for(i = 0; i < att.size; i++){ 
                arr[i] = att.strings[i]
                arrVal[i] = i
                colores[i] = -1
                arrMap[i] = i
        }
        //
        for(i = 0; i < sizeof(arr); i++){ 
                if(arr[i] == oldVal){
                        arr[i] = newVal
                }
        }
 
        string err = null
        AttrType at2 = modify(att, "Allocation", arr, arrVal, colores, arrMap, err)
        if(!null err){
                print "Failed: " err"\n"
        }
        else{
                infoBox at2.name " - Modified Successfully"
        }
}

 

Re: Function: Rename/Replace Enumeration Value of a DataType
Pekka_Makinen - Thu Oct 15 05:27:09 EDT 2015

Bjoern_Karpenstein - Thu Oct 15 05:21:04 EDT 2015

Hi thanks for your reply.

Only one question:

Is the following function save in the way, that enumeration values that already have been set in the module will not get lost?

void replaceAttributeTypeValue(Module m, string atName, string oldVal, string newVal){
    AttrType att = find(m, atName)
        //Declare Arrays Size
        int colores[att.size]
        int arrMap[att.size]
        string arr[att.size]
        int arrVal[att.size]
        
        int i
        //Populate Arrays
        for(i = 0; i < att.size; i++){ 
                arr[i] = att.strings[i]
                arrVal[i] = i
                colores[i] = -1
                arrMap[i] = i
        }
        //
        for(i = 0; i < sizeof(arr); i++){ 
                if(arr[i] == oldVal){
                        arr[i] = newVal
                }
        }
 
        string err = null
        AttrType at2 = modify(att, "Allocation", arr, arrVal, colores, arrMap, err)
        if(!null err){
                print "Failed: " err"\n"
        }
        else{
                infoBox at2.name " - Modified Successfully"
        }
}

 

In my experience just changing one existing enumerated value to other one in an attribute type to is safe. You might have problems if you delete invidual values from the type values list.